<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>系统管理--用户管理</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<link rel="stylesheet" href="css/chuchu/chuchu.css" type="text/css"></link>
<link rel="stylesheet" href="easyui/themes/icon.css" type="text/css"></link>
<link rel="stylesheet" href="easyui/themes/default/easyui.css"
	type="text/css"></link>
<script type="text/javascript" src="easyui/jquery-1.8.3.js"></script>
<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
<script type="text/javascript">
     	$(function(){
  			$("#add").dialog({closed:true});
  			$("#updatee").dialog({closed:true});	
  			$("#show").datagrid({
  				url:"users/findAll.do",
	  			title:"角色列表",
	  			striped:true,
	  			pagination:true,	//分页
  				pageList:[10,20,50],//可选择每页大小
	  			columns:[[
	  			{
	  			title:"排序",
	  			width:50,
	  			field:"id"
	  			},
	  			{
	  			title:"用户名",
	  			width:100,
	  			field:"name",
	  			},
	  			{
	  			title:"真实姓名",
	  			width:100,
	  			field:"realname"
	  			},
	  			{
	  			title:"角色",
	  			width:100,
	  			field:"rolename"
	  			},
	  			{
	  			title:"机构/部门",
	  			width:150,
	  			field:"deptname"
	  			},
	  			{
	  			title:"状态",
	  			width:100,
	  			field:"status",
	  			formatter:function (value){
					if(value==0){
						return "正常";
					}else if(value==2){
						return "冻结";
						}
					}
	  			},{
	  			title:"操作",
	  			width:150,
	  			field:"x",
	  			formatter:function(value,row){
	  				return "<a onclick='del("+row.id+")' href='javascript:void(0)'>删除</a>&nbsp<a onclick='update("+row.id+")' href='javascript:void(0)'>修改</a>";
	  			}
	  			}
	  			]],
	  			toolbar:[{text:"新增",iconCls:"icon-add",handler:function(){
	  				add();
	  			}}]	
  			});
  		});
		function add(){
		$("#add").dialog({
  			title:"新增",
  			width:480,
  			heigeht:200,
  			closed:false,
  			modal:true,
  			buttons:[{text:"确定",
  					handler:function(){
  						var data =  "name="+$("#name").val()+
  							"&password="+$("#password").val()+
  							"&realname="+$("#realname").val()+
  							"&deptid="+$("#deptname").val()+
  							"&sex="+$("#sex").val()+
  							"&positionid="+$("#positionname").val()+
  							"&status="+$("#status").val()+
  							"&roleid="+$("#rolename").val();						
  							$.post(
  								"users/add.do",
  								data,
  								function(data){
  									alert(data);
  									$("#add").dialog("close");
  									$("#show").datagrid("reload");
  								},
  								"text"
  							);
  					}
  					},
  					{text:"取消",
  					handler:function(){
  							$("#add").dialog("close");
  						}
  					}]
  		});
		}
		function del(value){
			$.messager.confirm("提示框", "你确定要删除吗?",function(r){
				if(r){
					var data = "id="+value;
						$.post(
			  				"users/delete.do",
			  				data,
			  				function(data){
			  				alert(data);
			  				$("#show").datagrid("reload");
			  				},
			  				"text"
			  			);
					}
			});
		};
		function update(value){
		$.post("users/findById.do","id="+value,function(data){
  				$("#name1").val(data.name);
  				$("#password1").val(data.password);
  				$("#realname1").val(data.realname);
  				$("#password1").val(data.password);
  				$("#sex1").val(data.sex);
  				$("#status1").val(data.status);
  			},"json");
			$("#updatee").dialog({
  			title:"修改",
  			width:400,
  			heigeht:200,
  			closed:false,
  			modal:true,
  			buttons:[{text:"确定",
  					handler:function(){
  						var data = "id="+value+
  							"&name="+$("#name1").val()+
  							"&password="+$("#password1").val()+
  							"&realname="+$("#realname1").val()+
  							"&deptid="+$("#deptname1").val()+
  							"&sex="+$("#sex1").val()+
  							"&positionid="+$("#positionname1").val()+
  							"&status="+$("#status1").val()+
  							"&roleid="+$("#rolename1").val();

  							$.post(
  								"users/update.do",
  								data,
  								function(data){
  									alert(data);
  									$("#updatee").dialog("close");
  									$("#show").datagrid("reload");
  								},
  								"text"
  							);
  					}
  					},
  					{text:"取消",
  					handler:function(){
  							$("#updatee").dialog("close");
  						}
  					}]
  		});
		};
		function show(){
	  		var name = $("#name2").val();
	  		var realname = $("#realname2").val();
	  		var data = "name="+name+
  						"&realname="+realname;
	  		$("#show").datagrid({
	  			url:"users/findByParam.do?"+data
	  		});
		};
		function processResult(data){
 				$("#imgShow").attr("src","upload/"+data);	
		}
     </script>
</head>

<body style="height: 500px">
	<div id="mainbody" >
		<p>
			<img src="css/chuchu/img/u89.png" id="img">&nbsp;&nbsp;<span>系统设置</span>
		</p>
		<div class="title">用户管理</div>
		<div class="content">
			<div id="tb">
				用户名：<input type="text" id="name2" name="name2"> 真实姓名：<input
					type="text" id="realname2" name="realname2"> 
					<a href="javascript:void(0);" onclick="show()" class="easyui-linkbutton" >查询</a>
			</div>
			
		</div>
		<div id="show"></div>
			
		<div id="update"></div>
	</div>
	<div id="add">
				<table class="dia">
					<tr>
						<td>登录名</td><td><input type="text" id="name" name="name"/></td>
					</tr>
					<tr>
						<td>密码</td><td><input type="text" id="password" name="password"/></td>
					</tr>
					<tr>
						<td>真实姓名</td><td><input type="text" id="realname" name="realname"/></td>
					</tr>
					<tr>
						<td>所在部门</td>
						<td>
							<select id="deptname">
							<option >请选择部门</option>
							<option value="1">人事部</option>		
							<option value="2">财务部</option>		
							<option value="3">技术部</option>		
							<option value="4">销售部</option>		
						</select>
						</td>
					</tr>
					<tr>
						<td>性别</td>
						<td>
						<input type="radio" checked="checked"  value="男" id="sex" name="sex" />男
						<input type="radio" value="女" id="sex" name="sex" />女
						</td>
					</tr>
					<tr>
						<td>职位</td>
						<td>
							<select id="positionname">
								<option>请选择职位</option>
								<option value="1">普通员工</option>	
								<option value="2">部门经理</option>		
								<option value="3">助理</option>		
								<option value="4">总监</option>		
								<option value="5">总经理</option>		
							</select>
						</td>
					</tr>
					<tr>
						<td>角色</td><td>
										<select id="rolename">
											<option value="1">普通用户</option>										
											<option value="2">人事专员</option>		
											<option value="3">部门经理</option>		
											<option value="4">公司领导</option>		
											<option value="5">系统管理员</option>		
										</select>
									</td>
					</tr>
					<tr>
						<td>状态</td>
						<td>
						<input type="radio" checked="checked"  id="status" name="status"  value="0"/>正常
						<input type="radio" id="status" name="status"  value="1" />冻结
						</td>
					</tr>
				</table>
			</div>
	
	<div id="updatee">
				<table>
					<tr>
						<td>登录名</td><td><input type="text" id="name1" name="name"/></td>
						
					</tr>
					<tr>
						<td>密码</td><td><input type="text" id="password1" name="password"/></td>
					</tr>
					<tr>
						<td>真实姓名</td><td><input type="text" id="realname1" name="realname"/></td>
					</tr>
					<tr>
						<td>所在部门</td>
						<td>
							<select id="deptname1">
							<option >请选择部门</option>
							<option value="1">人事部</option>		
							<option value="2">财务部</option>		
							<option value="3">技术部</option>		
							<option value="4">销售部</option>		
						</select>
						</td>
					</tr>
					<tr>
						<td>性别</td>
						<td>
						<input type="radio"  checked="checked" value="男" id="sex1" name="sex1" />男
						<input type="radio" value="女" id="sex1" name="sex1" />女
						</td>
					</tr>
					<tr>
						<td>职称</td>
						<td>
							<select id="positionname1">
								<option>请选择职称</option>
								<option value="1">普通员工</option>	
								<option value="2">部门经理</option>		
								<option value="3">助理</option>		
								<option value="4">总监</option>		
								<option value="5">总经理</option>		
							</select>
						</td>
					</tr>
					<tr>
						<td>角色</td><td>
										<select id="rolename1">
											<option value="1">普通用户</option>										
											<option value="2">人事专员</option>		
											<option value="3">部门经理</option>		
											<option value="4">公司领导</option>		
											<option value="5">系统管理员</option>		
										</select>
									</td>
					</tr>
					<tr>
						<td>状态</td>
						<td>
						<input type="radio" checked="checked"  id="status1" name="status1"  value="0"/>正常
						<input type="radio" id="status1" name="status1"  value="1" />冻结
						</td>
					</tr>
				</table>
			</div>

</body>
</html>
